package fr.unice.client;

import java.util.ArrayList;

import com.smartgwt.client.widgets.grid.ListGridRecord;

/**
 * Wrapper used by SmartGWT in order to fill the grid list of playlists.
 * 
 * @author PELLEGRINO Laurent
 * @author TROVATO Alexandre
 * 
 * @version 1.0
 */
public class PlaylistRecord extends ListGridRecord {
	public PlaylistRecord(Long id, String name, int nbAudioFiles,
			ArrayList<String> audioFileIDs) {
		this.setId(id);
		this.setName(name);
		this.setNbAudioFiles(nbAudioFiles);
		this.setAudioFileIDs(audioFileIDs);
	}

	public Long getId() {
		return (Long) super.getAttributeAsObject("id");
	}

	public String getName() {
		return super.getAttributeAsString("name");
	}

	public int getNbAudioFiles() {
		return super.getAttributeAsInt("nbAudioFiles");
	}

	@SuppressWarnings("unchecked")
	public ArrayList<String> getAudioFileIDs() {
		return (ArrayList<String>) super.getAttributeAsObject("audioFileIDs");
	}

	public void setAudioFileIDs(ArrayList<String> audioFileIDs) {
		super.setAttribute("audioFileIDs", audioFileIDs);
	}

	public void setId(Long id) {
		super.setAttribute("id", id);
	}

	public void setName(String name) {
		super.setAttribute("name", name);
	}

	public void setNbAudioFiles(int nb) {
		super.setAttribute("nbAudioFiles", nb);
	}

	public void add(String audioFileID) {
		ArrayList<String> audioFileIDs = this.getAudioFileIDs();
		if (audioFileIDs == null) {
			audioFileIDs = new ArrayList<String>();
		}
		audioFileIDs.add(audioFileID);
		this.setAudioFileIDs(audioFileIDs);
		this.setNbAudioFiles(this.getNbAudioFiles() + 1);
	}

	public void remove(String audioFileID) {
		ArrayList<String> audioFileIDs = this.getAudioFileIDs();
		audioFileIDs.remove(audioFileID);
		this.setAudioFileIDs(audioFileIDs);
		this.setNbAudioFiles(this.getNbAudioFiles() - 1);
	}
}
